﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using KL.UFrame.Core.Result;
using KL.UFrame.Data.Entities;
using KL.UFrame.Data.Models.Account;

namespace KL.UFrame.Data.Business.Account
{
    /// <summary>
    /// 用户账户相关业务接口.
    /// 特别注意：不要Api生命周期外调用UnityBootstrapper.Current.GetService<IAccountBusiness>()
    /// By：杨超
    /// </summary>
    public interface IAccountBusiness
    {
        /// <summary>
        /// 通过用户名和密码查询用户
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <returns>成功返回true，否则返回false</returns>
        Task<ApplicationUser> FindUserAsync(string userName, string password);

        /// <summary>
        /// 根据用户名获取用户信息
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        Task<UserInfoModel> GetUserInfoByNameAsync(string userName);

        /// <summary>
        /// 根据用户名获取用户角色组
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        Task<string[]> GetUserRolesAsync(string userId);

        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        Task<bool> CreateUserAsync(UserRegisterModel model);

        /// <summary>
        /// 找回密码
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        Task<bool> SetPassordAsync(ResetPasswordModel model);

        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        Task<bool> ChangePassordAsync(ChangePasswordModel model);

        /// <summary>
        /// 分页查找用户列表
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        Task<ResultMessage<List<UserInfoModel>>> GetAllAsync(string phone, int pageIndex, int pageSize);

        /// <summary>
        /// 切换用户锁定状态
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        Task<bool> ToggleLockAsync(string userId);

        /// <summary>
        /// 切换用户角色
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="role"></param>
        /// <returns>true：添加了角色 ，false:删除了角色</returns>
        Task<bool> ToggleRoleAsync(string userId, string role);

        /// <summary>
        /// 获取角色列表，并标示此用户是否授权
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        Task<List<UserRoleModel>> GetRolesAsync(string userId);

        /// <summary>
        /// 新增角色
        /// </summary>
        /// <param name="roleName"></param>
        /// <returns>角色Id</returns>
        Task<string> CreateRoleAsync(string roleName);

        /// <summary>
        /// 修改昵称
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        Task<int> ChangeNicknameAsync(string userId, string name);

        /// <summary>
        /// 后台创建用户
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        Task<string> CreateUserFromBackendAsync(UserRegisterModel model);
    }
}